import http from '@/utils/request'

export const orderApi = {
    // 创建订单
    createOrders(params) {
        return http.post('OrdersController/createOrders', {
            userName: params.userName,
            businessId: parseInt(params.businessId),
            daId: parseInt(params.daId),
            orderTotal: parseFloat(params.orderTotal),
            orderItems: params.orderItems.map(item => ({
                foodId: parseInt(item.foodId),
                quantity: parseInt(item.quantity),
                foodPrice: parseFloat(item.foodPrice)
            }))
        })
    },

    // 获取订单列表
    listOrdersByUserId(params) {
        return http.post('OrdersController/listOrdersByUserId', {
            userName: params.userName
        })
    },

    // 获取订单详情
    getOrdersById(params) {
        return http.post('OrdersController/getOrdersById', {
            orderId: parseInt(params.orderId)
        })
    },

    // 获取订单明细
    getOrderDetailetByOrderId(orderId) {
        return http.post('OrdersController/getOrderDetailetByOrderId', {
            orderId
        })
    },

    // 更新订单状态
    updateOrderState(params) {
        return http.post('OrdersController/updateOrderState', {
            orderId: params.orderId,
            orderState: params.orderState
        })
    }
}

export default orderApi 